# python的迭代抽象程度比较高
# 字典可以这样迭代取key
# 字典顺序可能会乱
from collections import Iterable
d = {'name': 'Tom', 'age': 18, 'gender': 'male'}
for key in d:
    print(key)

# 字典可以这样迭代取value
for value in d.values():
    print(value)

# 字典可以这样迭代取key,value
for k, v in d.items():
    print('key:%s,value:%s' % (k, v))

# 字符串也可以被迭代
for ch in 'Thomas':
    print(ch)

# 判断一个对象是否可以被迭代
result = isinstance(d, Iterable)
print(result)

# 带上下标循环
for i, value in enumerate(d):
    print(i, value)

# 迭代多个变量
l = [(1, 1), (2, 2), (6, 7)]
for x, y in l:
    print(x, y)
